package com.nuanshui.heatedloan.fund.integration.pay.execute.sysexecute;

import com.nuanshui.framework.utils.LogUtil;
import com.nuanshui.heatedloan.fund.integration.form.PayForm;
import com.nuanshui.heatedloan.fund.integration.pay.annotation.PayHandlerComponent;
import com.nuanshui.heatedloan.fund.integration.pay.execute.PayConfirmHandler;
import com.nuanshui.heatedloan.fund.model.PayResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 日志记录功能
 * @param 
 * @author guohao
 * @date 2017年1月11日 上午11:57:35
 * @since $
 */
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@PayHandlerComponent(order=99,value="loggingPayConfirmHandler")
public class LoggingPayConfirmHandler  implements PayConfirmHandler{

    private Logger logger  = LoggerFactory.getLogger("pay_confirm");
	
	private PayConfirmHandler payConfirmHandler;
	@Override
	public PayResult executePaymentConfirm(PayForm payForm) {
		
		LogUtil.info(logger, "----------执行支付回调确认功能----------");
		LogUtil.info(logger, String.format("----------支付的支付号%s----------", payForm.getOrderNum()) );
		LogUtil.info(logger, String.format("----------支付类型%s----------", payForm.getPayType()));
		LogUtil.info(logger, String.format("----------支付金额%s----------", payForm.getPayPrice()));
		LogUtil.info(logger, String.format("----------确认的用户%s----------", payForm.getUserId()));//只有余额支付此字段才又结果

		PayResult payResult =  payConfirmHandler.executePaymentConfirm(payForm);
		
		if(payResult.isSuccess())  {
			LogUtil.info(logger, "支付确认成功      ");//只有余额支付此字段才又结果
		}else {
			LogUtil.info(logger, "支付确认失败  失败错误号  "+payResult.getStatus());
		}
		LogUtil.info(logger, "----------执行支付回调确认功能结束----------");
		return payResult;
		
		
		
	}

	@Override
	public void setPayConfirmHandler(PayConfirmHandler payConfirmHandler) {
		this.payConfirmHandler = payConfirmHandler;
		
	}
	
	public static void main(String[] args) {
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		
		System.out.println(sf.format(new Date(1484795160000l)));
	}

}
